const { app, Menu, BrowserWindow } = require('electron');
const isDev = require('electron-is-dev');
const AppWindow = require('./src/utils/AppWindow.js');
const menuItems = require('./menu.config.js');
const path = require('path');
let newwin;
const ipc = require('electron').ipcMain
app.on('ready', () => {
  const mainWindowConfig = {
    width: 800,
    height: 600,
    x: 1,
    y: 1
  };
  const urlLocation = isDev
    ? 'http://localhost:3000'
    : `file://${path.join(__dirname, './index.html')}`;
  mainWindow = new AppWindow(mainWindowConfig, urlLocation);
  mainWindow.on('closed', () => {
    mainWindow = null;
  });
  const menu = Menu.buildFromTemplate(menuItems);
  // Menu.setApplicationMenu();
});



ipc.on('add', () => {
  newwin = new BrowserWindow({
    width: 1280,
    height: 960,
    frame: true,
    //win是主窗口
  })
  newwin.loadURL("http://bynesjx.yhzhg.cn/"); //new.html是新开窗口的渲染进程
  newwin.webContents.openDevTools()
  const { session } = require('electron')
  newwin.on('closed', () => { newwin = null })
  session.defaultSession.cookies.get({ url: 'http://bynesjx.yhzhg.cn' }, (err, cookies) => {
    alert(cookies)
  })
})
ipc.on('closeqinshi', () => {
  newwin.close();
})